
// CalendarManager.m
#import "NAManager.h"

NSString * const DOWNLOAD_ENVENT = @"DOWNLOAD_ENVENT";
NSString * const VEDIO_DATA_ENVENT = @"VEDIO_DATA_ENVENT";

NSString * const ENVENT_EMITTED = @"ENVENT_EMITTED";
NSString * const ENVENT_REQUEST_DATA = @"ENVENT_REQUEST_DATA";

@implementation NAManager
{
  bool hasListeners;
}

RCT_EXPORT_MODULE();

- (NSArray<NSString *> *)supportedEvents {
  return @[ENVENT_REQUEST_DATA];
}

// 在添加第一个监听函数时触发
- (void)startObserving
{
//  Contants *contants =  [[Contants alloc] init];
//  NSLog(@"---startObserving---");
  hasListeners = YES;
  [[NSNotificationCenter defaultCenter] addObserver:self
                                           selector:@selector(emitEventInternal:)
                                               name:ENVENT_EMITTED
                                             object:nil];
}

- (NSDictionary *)constantsToExport
{
  return @{
           @"ENVENT_REQUEST_DATA":ENVENT_REQUEST_DATA,
           @"VEDIO_DATA_ENVENT":VEDIO_DATA_ENVENT,

           };
}

- (void)stopObserving
{
//  NSLog(@"---stopObserving---");
  hasListeners = NO;
  [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)emitEventInternal:(NSNotification *)notification
{
  
  if (hasListeners) { // Only send events if anyone is listening
    [self sendEventWithName:ENVENT_REQUEST_DATA
                       body:notification.userInfo];
  }
}

+ (void)emitEventWithName:(NSString *)name andPayload:(NSDictionary *)payload
{
  [[NSNotificationCenter defaultCenter] postNotificationName:ENVENT_EMITTED
                                                      object:self
                                                    userInfo:payload];
}

//+ (MFBrowserManager*)fBrowserManager
//{
//  static MFBrowserManager* instance = nil;
//  static dispatch_once_t once;
//
//  dispatch_once(&once, ^{
//    instance = [[self.class alloc] init];
//  });
//  return instance;
//}
+ (BOOL)requiresMainQueueSetup
{
  return YES;  // only do this if your module initialization relies on calling UIKit!
}
@end
